package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.BonusTransactionHandler;
import com.cungmua.app.model.request.BonusTransactionRequest;
import com.cungmua.app.model.response.BonusTransactionResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 7/31/14.
 */
public class BonusTransactionTask extends AuthenticatedTask<BonusTransactionRequest,Void,BonusTransactionResponse> {
    private Context context;
    private BonusTransactionHandler handler;

    public BonusTransactionTask(Context context, BonusTransactionHandler handler) {
        this.context = context;
        this.handler = handler;
    }
    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected BonusTransactionResponse doInBackground() throws RetrofitError {
        BonusTransactionRequest request=params[0];
        return  CungMuaAPI.getService().listBonusTransactions(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(BonusTransactionResponse bonusTransactionResponse) {
        handler.onBonusTransaction(bonusTransactionResponse);
    }
}
